package com.love.driver.service.impl;

import java.util.List;

import com.love.common.core.constant.SecurityConstants;
import com.love.common.core.domain.R;
import com.love.common.core.utils.DateUtils;
import com.love.common.security.utils.SecurityUtils;
import com.love.driver.enums.DriverTypeEnum;
import com.love.system.api.RemoteUserService;
import com.love.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.love.driver.mapper.LoveDriverInfoMapper;
import com.love.driver.domain.LoveDriverInfo;
import com.love.driver.service.ILoveDriverInfoService;

/**
 * 代驾司机信息档案Service业务层处理
 * 
 * @author love
 * @date 2025-09-13
 */
@Service
public class LoveDriverInfoServiceImpl implements ILoveDriverInfoService 
{
    @Autowired
    private LoveDriverInfoMapper loveDriverInfoMapper;
    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 查询代驾司机信息档案
     * 
     * @param driverId 代驾司机信息档案主键
     * @return 代驾司机信息档案
     */
    @Override
    public LoveDriverInfo selectLoveDriverInfoByDriverId(Long driverId)
    {
        return loveDriverInfoMapper.selectLoveDriverInfoByDriverId(driverId);
    }

    /**
     * 查询代驾司机信息档案列表
     * 
     * @param loveDriverInfo 代驾司机信息档案
     * @return 代驾司机信息档案
     */
    @Override
    public List<LoveDriverInfo> selectLoveDriverInfoList(LoveDriverInfo loveDriverInfo)
    {
        return loveDriverInfoMapper.selectLoveDriverInfoList(loveDriverInfo);
    }

    /**
     * 新增代驾司机信息档案
     * 
     * @param loveDriverInfo 代驾司机信息档案
     * @return 结果
     */
    @Override
    public int insertLoveDriverInfo(LoveDriverInfo loveDriverInfo)
    {
        loveDriverInfo.setCreateTime(DateUtils.getNowDate());
        return loveDriverInfoMapper.insertLoveDriverInfo(loveDriverInfo);
    }

    /**
     * 代驾司机注册
     *
     * @param loveDriverInfo 代驾司机信息档案
     * @return 结果
     */
    @Override
    public int registerDriverInfo(LoveDriverInfo loveDriverInfo)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        Long userId = currentUser.getUserid();
        // 查询用户信息
        R<LoginUser> sysUser = remoteUserService.userId(userId, SecurityConstants.INNER);
        loveDriverInfo.setDriverName(sysUser.getData().getSysUser().getUserName());
        loveDriverInfo.setDriverPhone(sysUser.getData().getSysUser().getPhonenumber());
        loveDriverInfo.setDriverId(userId);
        loveDriverInfo.setStatus(DriverTypeEnum.UNREGISTERED.getCode());
        loveDriverInfo.setCreateTime(DateUtils.getNowDate());
        return loveDriverInfoMapper.insertLoveDriverInfo(loveDriverInfo);
    }

    /**
     * 修改代驾司机信息档案
     * 
     * @param loveDriverInfo 代驾司机信息档案
     * @return 结果
     */
    @Override
    public int updateLoveDriverInfo(LoveDriverInfo loveDriverInfo)
    {
        loveDriverInfo.setUpdateTime(DateUtils.getNowDate());
        return loveDriverInfoMapper.updateLoveDriverInfo(loveDriverInfo);
    }

    /**
     * 批量删除代驾司机信息档案
     * 
     * @param driverIds 需要删除的代驾司机信息档案主键
     * @return 结果
     */
    @Override
    public int deleteLoveDriverInfoByDriverIds(Integer[] driverIds)
    {
        return loveDriverInfoMapper.deleteLoveDriverInfoByDriverIds(driverIds);
    }

    /**
     * 删除代驾司机信息档案信息
     * 
     * @param driverId 代驾司机信息档案主键
     * @return 结果
     */
    @Override
    public int deleteLoveDriverInfoByDriverId(Integer driverId)
    {
        return loveDriverInfoMapper.deleteLoveDriverInfoByDriverId(driverId);
    }
}
